package com.onepower.core.modules.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.onepower.core.domain.mapper.MatchScoreInfoMapper;
import com.onepower.core.domain.response.MatchScoreInfo;
import com.onepower.core.exception.BizException;
import com.onepower.core.modules.repository.entity.MatchScore;
import com.onepower.core.modules.repository.mapper.MatchScoreMapper;
import com.onepower.core.modules.service.IMatchScoreService;
import com.onepower.core.result.BizResultCode;
import org.springframework.dao.DuplicateKeyException;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service
public class MatchScoreServiceImpl extends ServiceImpl<MatchScoreMapper, MatchScore> implements IMatchScoreService {
    @Override
    public MatchScoreInfo getMatchScore(int matchId, int matchAdminId) {
        MatchScore score = baseMapper.selectScoreByMatchScheduleId(matchAdminId, matchId);
        return MatchScoreInfoMapper.MAPPER.converter(score);
    }

    @Override
    public List<Map<String,Object>> getMatchScoreList(int matchScheduleId,int scoreType) {
        List<Map<String,Object>> matchScoreList = baseMapper.selectScoreList(matchScheduleId,scoreType);
        return matchScoreList;
    }

    @Override
    public void saveMatchScore(MatchScore matchScore) {
        try {
             baseMapper.insert(matchScore);
        } catch (DuplicateKeyException e) {
            throw new BizException(BizResultCode.MATCH_SCORE_HAS_JUDGE);
        }
    }

    @Override
    public Map<String, Object> avgScore(int matchScheduleId,int scoreType) {
        return baseMapper.avgScore(matchScheduleId,scoreType);
    }

    @Override
    public Map<String,Object> removeMaxAndMinAvgExpressiveness(int matchScheduleId,int scoreType){
        return baseMapper.removeMaxAndMinAvgExpressiveness(matchScheduleId,scoreType);
    }

    @Override
    public Map<String,Object> removeMaxAndMinAvgAccuracy(int matchScheduleId,int scoreType){
        return baseMapper.removeMaxAndMinAvgAccuracy(matchScheduleId,scoreType);
    }

    @Override
    public Map<String,Object> removeMaxAndMinSumSocre(int matchScheduleId,int scoreType){
        return baseMapper.removeMaxAndMinSumSocre(matchScheduleId,scoreType);
    }

    @Override
    public Map<String, Object> sumScore(int matchScheduleId,int scoreType) {
        return baseMapper.sumScore(matchScheduleId,scoreType);
    }

    @Override
    public Integer matchScoreCount(int matchScheduleId,int scoreType) {
        return baseMapper.matchScoreCount(matchScheduleId,scoreType);
    }

    @Override
    public Map<String, Object> matchScoreWinnerCount(int matchScheduleId,int scoreType) {
        return baseMapper.matchScoreWinnerCount(matchScheduleId,scoreType);
    }

    @Override
    public MatchScore matchRefereeScore(int matchScheduleId, int refereeId, int scoreType) {
        return baseMapper.matchRefereeScore(matchScheduleId,refereeId,scoreType);
    }

    @Override
    public List<Map<String, Object>> selectRefereeScoreList(int matchId, int matchAdminId, int matchScheduleId,int scoreType) {
        return baseMapper.selectRefereeScoreList(matchId,matchAdminId,matchScheduleId,scoreType);
    }

    @Override
    public List<Map<String, Object>> orderAccuracy(int matchScheduleId,int scoreType) {
        return baseMapper.orderAccuracy(matchScheduleId,scoreType);
    }

    @Override
    public List<Map<String, Object>> orderExpressiveness(int matchScheduleId,int scoreType) {
        return baseMapper.orderExpressiveness(matchScheduleId,scoreType);
    }

    @Override
    public List<Map<String, Object>> orderAccuracyAll(int matchScheduleId) {
        return baseMapper.orderAccuracyAll(matchScheduleId);
    }

    @Override
    public List<Map<String, Object>> orderExpressivenessAll(int matchScheduleId) {
        return baseMapper.orderExpressivenessAll(matchScheduleId);
    }

    @Override
    public Map<String, Object> sumScoreAll(int matchScheduleId) {
        return baseMapper.sumScoreAll(matchScheduleId);
    }
}
